
** Figure 6 : Dynamic effects based on exposure to shock

use "$datadir\ewallet\maindata.dta", clear
	
	qui foreach var of varlist logamount  lognumfirms lognewfirms {
		statsby eff_1=_b[timeid1Xinvshare_sd] eff_2=_b[timeid2Xinvshare_sd] eff_3=_b[timeid3Xinvshare_sd] eff_4=_b[timeid4Xinvshare_sd] eff_5=_b[timeid5Xinvshare_sd] eff_6=_b[timeid6Xinvshare_sd] eff_7=_b[timeid7Xinvshare_sd] eff_8 =_b[timeid8Xinvshare_sd] eff_9 =_b[timeid9Xinvshare_sd] eff_10 =_b[timeid10Xinvshare_sd] eff_11=_b[timeid11Xinvshare_sd] eff_12 =_b[timeid12Xinvshare_sd] eff_13 =_b[timeid13Xinvshare_sd] eff_14 =_b[timeid14Xinvshare_sd] se_1 =_se[timeid1Xinvshare_sd] se_2 =_se[timeid2Xinvshare_sd] se_3 = _se[timeid3Xinvshare_sd] se_4 =_se[timeid4Xinvshare_sd] se_5 =_se[timeid5Xinvshare_sd] se_6 =_se[timeid6Xinvshare_sd] se_7 =_se[timeid7Xinvshare_sd] se_8 =_se[timeid8Xinvshare_sd] se_9 =_se[timeid9Xinvshare_sd] se_10 =_se[timeid10Xinvshare_sd] se_11 =_se[timeid11Xinvshare_sd] se_12 =_se[timeid12Xinvshare_sd] se_13 =_se[timeid13Xinvshare_sd] se_14 =_se[timeid14Xinvshare_sd] , saving("$datadir\dynamictemp`var'.dta", replace): reghdfe  `var' timeid*Xinvshare_sd if $filters , a($fe $controls##i.time_id) cluster(district_id)
	}

foreach var in logamount  lognumfirms lognewfirms { 
	use "$datadir\dynamictemp`var'.dta",clear
	  gen temp="`var'"
	  local name="`var'"
		if temp=="logamount" {
			local name= "amount transacted"
			local i = 1
			local y_range "-3(3)9"
			local upper 9
			local lower -3
			local numgraph 1
		}
		if temp=="lognumfirms" {
			local name= "# of active firms"
			local i = 3
			local y_range "-1(1)3"
			local upper 3
			local lower -1 
			local numgraph 2
		}
	
		if temp=="lognewfirms" {
			local name= "# of new adopters"
			local i = 4
			local y_range "-1(1)3"
			local upper 3
			local lower -1 
			local numgraph 3
		}
		   
	  gen i=1
	  reshape long eff_ se_ , i(i) j(period)
	  drop i
	  rename eff_ eff
	  rename se_ se
	  tset period
	  gen t_10=1.65
	  gen t_5=1.96
	  
	  foreach num in 5 10 {
	  gen low_bound_`num'=eff-(t_`num'*se)
	  gen up_bound_`num'=eff+(t_`num'*se)
	 }
	 replace period = period-6
	
	graph set window fontface "Garamond"
	g upper = `upper'
	local barcall upper period if inrange(period, 0.5, 3.5), bcolor(gray%20) lcolor(gray%5) base(`lower') lwidth(0)
	twoway (bar `barcall') (rcap up_bound_5 low_bound_5 period, lcolor(gray) lstyle(ci)) (scatter eff period, lcolor(black) mcolor(black) msymbol(circle) msize(medium)) , ///
	legend(off) graphregion(color(white)) ylab(`y_range',nogrid) xlab(-5(1)8)  yline(0, lcolor(black) lwidth(thin)) ///
	xtitle("Time") ytitle("Effect on `name'") xline(0.48 3.52, lcolor(black) lwidth(thin) lpattern(dash)) plotregion(lcolor(black) margin(b=0.25 t=0.25))
	graph export "$outputdir_fig\Figure_6_`numgraph'.pdf", as(pdf) replace
	
	
	erase "$datadir\dynamictemp`var'.dta"
}
